<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span>固定资产采购进程</span>
      </div>
      <el-table v-loading="loading" :data="list" row-key="id">
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column prop="odd" label="申请单号"></el-table-column>
        <el-table-column prop="name" label="固定资产名称"></el-table-column>
        <el-table-column prop="model" label="规格型号"></el-table-column>
        <el-table-column prop="number" label="采购数量"></el-table-column>
        <el-table-column
          prop="finishNumber"
          label="已采购数量"
        ></el-table-column>
        <el-table-column label="采购进度" width="100">
          <template slot-scope="scope">
            {{
              ((scope.row.finishNumber / scope.row.number) * 100).toFixed(2) +
              "%"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="purchaseState" label="采购状态" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.purchase_state"
              :value="scope.row.purchaseState"
            />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-shopping-cart-1"
              @click="handleAdd(scope.row)"
              >购入</el-button
            >

            <el-button
              size="mini"
              type="text"
              icon="el-icon-share"
              @click="
                () => {
                  $router.push({
                    path: '/base-log/log/purchase',
                    query: { id: scope.row.id },
                  });
                }
              "
            >
              日志
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="queryParams.total > 0"
        :total="queryParams.total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <AddProcess ref="dialogRef" @refresh="getList"></AddProcess>
  </div>
</template>

<script>
import { page } from "@/api/prod/purchase/process";
import AddProcess from "./components/addProcess";

export default {
  name: "Plan",
  dicts: ["purchase_state"],
  components: {
    AddProcess,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表格树数据
      list: [],
      // 请求参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // 总数
        total: 0,
      },
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询采购进程列表 */
    getList() {
      this.loading = true;
      page({}).then((response) => {
        this.list = response.data;
        this.queryParams.total = response.info.total;
        this.loading = false;
      });
    },

    /** 新增按钮操作 */
    handleAdd(row) {
      this.$refs["dialogRef"].show("购入", row?.id);
    },
  },
};
</script>

<style>
</style>